<script type="text/javascript">
Ext.onReady(function(){

    RM_MyReservations_List_calendarStore = new Ext.data.JsonStore({
        storeId: 'calendarStore',
        url: RM.Common.AssembleURL({
            controller: 'MyReservations_Planner',
            action: 'getcalendarsJson'
        }),
        root: 'calendars',
        idProperty: Ext.ensible.cal.CalendarMappings.CalendarId.mapping || 'id',
        fields: Ext.ensible.cal.CalendarRecord.prototype.fields.getRange(),
        remoteSort: true,
        sortInfo: {
            field: Ext.ensible.cal.CalendarMappings.Title.name,
            direction: 'ASC'
        }
    });
    RM_MyReservations_List_calendarStore.load(); // preload

    RM_MyReservations_List_proxy = new Ext.data.HttpProxy({
        disableCaching: false, // no need for cache busting when loading via Ajax
        api: {
            read: RM.Common.AssembleURL({
                controller: 'MyReservations_Planner',
                action: 'getdataJson'
            })
        },
        listeners: {
            exception: function(proxy, type, action, o, res, arg){
                var msg = res.message ? res.message : Ext.decode(res.responseText).message;
                RM.Common.Message.msg(RM.Translate.Common.Error, msg, 8,  "RM_MessagePopup" );
            }
        }
    });

    RM_MyReservations_List_reader = new Ext.data.JsonReader({
        totalProperty: 'total',
        successProperty: 'success',
        idProperty: 'id',
        root: 'data',
        messageProperty: 'message',
        fields: Ext.ensible.cal.EventRecord.prototype.fields.getRange()
    });

    RM_MyReservations_List_writer = new Ext.data.JsonWriter({
        encode: true,
        writeAllFields: true
    });

    RM_MyReservations_List_store = new Ext.ensible.cal.EventStore({
        id: 'event-store',
        restful: false,
        proxy: RM_MyReservations_List_proxy,
        reader: RM_MyReservations_List_reader,
        writer: RM_MyReservations_List_writer,
        autoLoad: true
    });

    if (typeof(RM_MyReservations_List_Grid) !== 'undefined') {
        RM_MyReservations_List_Grid.getSelectionModel().addListener(
            'rowselect',
            function(selectionModel, rowNumber, record) {
                RM_MyReservations_Selected_startDate = record.data.start_date.add(Date.DAY, -5).format('Y-m-d');
                RM_MyReservations_Selected_endDate = record.data.end_date.add(Date.DAY, 5).format('Y-m-d');
                RM_MyReservations_Selected_unit_id = 2;
                RM_MyReservations_List_calendarStore.reload();
                RM_MyReservations_List_store.reload();
            }
        );
    }

    RM_MyReservations_List_planner = new Ext.Panel({
        id: 'rm_myreservations_list_planner_parent_panel',
        renderTo: 'rm_myreservations_list_planner',
        items: [
            new Ext.ensible.cal.CalendarPanel({
                height: 500,
                id: 'rm_myreservations_list_planner_calendar',
                eventStore: RM_MyReservations_List_store,
                calendarStore: RM_MyReservations_List_calendarStore,
                title: RM.Translate.User.MyReservations.Planner.YourReservations,
                renderTo: "rm_myreservations_list_planner_panel"
            })
        ]
    });

});
</script>
<!-- Begin: Ext Scheduler -->
<!-- Extensible includes -->
<link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/resources/css/extensible-all.css" />
<?php
// set if the js files are loaded from debug or live(compressed)...
if ((int)Zend_Registry::get('config')->get('js')->get('debug')->get('user') == 1) {
    ?>
    <script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/extensible-all-debug.js"></script>
    <?php
} else {
    ?>
    <script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/extensible-all.js"></script>
    <?php
}
?>
<!-- Page-specific includes -->
<link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/resources/css/calendar.css"/>
<script type="text/javascript" src="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/system/js/libs/ext_addons/extensible/calendar.js"></script>

<div id="<?php echo $this->panel->getDivID() ?>" >
    <div align="center">
        <div id="rm_myreservations_list_planner_panel"></div>
    </div>
</div>